package com.woniuxy.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 马宇航
 * @Description: 延迟交换机配置
 * @DateTime: 22/10/20/0020 16:22
 * @Component: 成都蜗牛学苑
 **/
@Configuration
public class DelayConfig {
    //只能通过自定义交换机来进行配置 延迟交换机
    @Bean
    public CustomExchange delayExchange11(){
        Map<String,Object> args = new HashMap<>();
        //设置参数，基于直连交换机实现的延迟交换机
        args.put("x-delayed-type","direct");
        return new CustomExchange("delayExchange","x-delayed-message",true,false,args);
    }
    //定义普通队列
    @Bean
    public Queue nomalQueue11(){
        return new Queue("delayQueue",true,false,false);
    }
    //绑定交换机与队列
    @Bean
    public Binding bindingDelay11(){
        return BindingBuilder.bind(nomalQueue11()).to(delayExchange11()).with("delay").noargs();
    }
}
